package cn.com.nes.common.em;

import cn.com.nes.common.exception.MissBusinessParameterException;
import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 工单状态
 * @author lux
 */
public enum EvaluationEnum {
    /**
     * 待派单
     */
    _01("01", "维修不及时", true),
    /**
     * 待支援
     */
    _0101("0101", "当日4小时以上上门维修", true),
    /**
     * 处理中
     */
    _0102("0102", "隔天上门维修", true),
    /**
     * 已完成
     */
    _0103("0103", "三天或三天以上上门维修", true),
    /**
     * 已关闭
     */
    _0104("0104", "未上门、电话指导", true),
    /**
     * 已拒单
     */
    _02("02", "无法联系维修师傅", true),
    /**
     * 维修-待回访
     */
    _03("03", "维修次数频繁", true),
    /**
     * 安装 -待审核
     */
    _04("04", "未解决问题", true),
    _05("05", "暂时解决问题", true),
    _06("06", "保内收费", true),
    _07("07", "保外收费", true),
    _0701("0701", "收取上门或维修费用", true),
    _0702("0702", "接受配件价格", true),
    _0703("0703", "认为配件太贵", true),
    _0704("0704", "乱换件", true),
    _08("08", "维修师傅态度不好", true),
    _09("09", "已修好", true),
    ;

    private String key;

    private String val;

    @Getter
    private Boolean isComplete; // 当卡状态码对应的工单是否已安装完成

    EvaluationEnum(String key, String val, Boolean isComplete) {
        this.key = key;
        this.val = val;
        this.isComplete = isComplete;
    }

    public String getVal() {
        return val;
    }

    public String getKey() {
        return key;
    }

    public static String getVal(String key) {
        Map<String, String> map = Arrays.stream(values())
                .collect(Collectors.toMap(EvaluationEnum::getKey, EvaluationEnum::getVal));
        return ObjectUtil.isNull(key) ? "" : map.get(key);
    }

    // 获取安装完成状态对应值的列表
    public static List<String> getStatusList(Boolean isComplete) {
        if (ObjectUtil.isNull(isComplete)) {
            throw new MissBusinessParameterException("isComplete must not null");
        }

        return Arrays.stream(values())
                .filter(n -> isComplete.equals(n.getIsComplete()))
                .map(EvaluationEnum::getKey)
                .collect(Collectors.toList());
    }

    // 按状态获取工单是否已完成
    public static Boolean getIsComplete(Integer key) {
        Map<String, Boolean> map = Arrays.stream(values())
                .collect(Collectors.toMap(EvaluationEnum::getKey, EvaluationEnum::getIsComplete));
        return !ObjectUtil.isNull(key) && map.get(key.toString());
    }

}
